package com.pktechan.api.controller;

import com.pktechan.api.entity.CustBase;
import com.pktechan.api.utils.FastDfsHttpUtil;
import com.pktechan.api.utils.FileResponseData;
import com.pktechan.api.utils.HtmlUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

/**
 * TMD企鹅要改专用通道去获取头像与昵称，只是添加了大家的麻烦，一点意义都没有，想出这个主意的人脑子肯定进屎了
 */

@Controller
public class AvatarApi {
    private static final Logger logger = LoggerFactory.getLogger(AvatarApi.class);

    @PostMapping("/uploadAvatar")
    public ResponseEntity upload(HttpServletResponse response, @RequestParam("avatarUrl") MultipartFile avatarUrl) throws Exception {
        FileResponseData fileResponseData = FastDfsHttpUtil.uploadFile(avatarUrl, "微信头像");
        logger.info("上传头像成功，文件地址为：", fileResponseData.getHttpUrl());
        return ResponseEntity.ok(fileResponseData.getHttpUrl());
    }
}
